﻿<!--<script type='text/html' template>
</script>-->
<link rel="stylesheet" href="../src/lib/extend/umeditor/themes/default/css/umeditor.css" media="all">

<title>权限设置</title>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>权限设置</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">权限设置</div>

                <div class="layui-card-body" pad15>
                    <!--<div class="layui-btn-container">
                        <button type="button" class="layui-btn layui-btn-sm" lay-demo="getChecked">获取选中节点数据</button>
                        <button type="button" class="layui-btn layui-btn-sm" lay-demo="setChecked">勾选指定节点</button>
                        <button type="button" class="layui-btn layui-btn-sm" lay-demo="reload">重载实例</button>
                    </div>-->
                    <div class="layui-form" wid100 lay-filter="">
                        <blockquote class="layui-elem-quote">
                            <script type='text/html' template>
                                当前选中用户：{{decodeURI(layui.router().search.RoleName)}}
                            </script>
                        </blockquote>
                        <div id="treeList" class="demo-tree-more"></div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="set_website" onclick="Save();">确认保存</button>
                                <button class="layui-btn" lay-submit lay-filter="set_website" onclick="javascript:window.location.href = '#/admin/Portal_Right_Role/'">返回</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['tree', 'util'], function () {
        var tree = layui.tree
        , layer = layui.layer
        , util = layui.util
        SetTree();
    });

    function SetTree() {
        layui.use(['admin', 'tree', 'table'], function () {
            var tree = layui.tree;
            var admin = layui.admin;
            var table = layui.table;
            var rou = layui.router();
            admin.req({
                url: layui.setter.APIUrl + '/admin/right_RoleRightMgr/GetRoleRight' //实际使用请改成服务端真实接口
                              , data: { "RoleID": rou.search.RoleID }
                                  , type: "post"
                              , done: function (res) {
                                  var data1 = res.Data.MenuAll;//返回的菜单子集名称叫list，转换为树形所需要的children
                                  var jsonStr1 = JSON.stringify(data1).replace(/list/g, "children");
                                  var rtnData = JSON.parse(jsonStr1);
                                  //常规用法
                                  tree.render({
                                      id: 'treeList1',
                                      elem: '#treeList', //默认是点击节点可进行收缩
                                      data: rtnData,
                                      showCheckbox: true  //,是否显示复选框
                                  });

                                  var strRoleRight = res.Data.RoleRight;//返回的菜单子集名称叫list，转换为树形所需要的children
                                  if (strRoleRight != "")
                                      tree.setChecked('treeList1', strRoleRight.split(',')); //批量勾选 id 为 2、3 的节点
                              }
            });


        });

    }
    function Save() {
        layui.use(['admin', 'tree'], function () {
            var admin = layui.admin;
            var tree = layui.tree;
            var rou = layui.router();

            var checkedData = tree.getChecked('treeList1'); //获取选中节点的数据
            var jsonStr1 = JSON.stringify(checkedData).replace(/children/g, "list");
            admin.req({
                url: layui.setter.APIUrl + '/admin/right_RoleRightMgr/SetRoleRight', //实际使用请改成服务端真实接口
                data: { "RoleRight": jsonStr1, "RoleID": rou.search.RoleID },
                type: "post",
                done: function (res) {
                    layer.msg('设置成功');
                    setTimeout(function () {
                        window.location.href = "#/admin/Portal_Right_Role/";
                    }, 1000);
                }
            });
        });
    }
</script>
